package cn.fzkj.gulimall.auth.controller;

import cn.fzkj.common.utils.R;
import cn.fzkj.gulimall.auth.entity.base.SocialUser;
import cn.fzkj.gulimall.auth.feign.MemberFeignService;
import cn.fzkj.gulimall.auth.strategy.factory.LoginStrategyFactory;
import cn.fzkj.gulimall.auth.strategy.login.LoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;


/**
 * @DESCRIPTION 第三方登陆接口
 * @Author yaya
 * @DATE 2022/8/27
 */
@RestController
@RequestMapping(value = "/oauth")
public class OauthController {

    @Autowired
    private MemberFeignService memberFeignService;

    @RequestMapping(value = "/{loginType}", method = RequestMethod.GET)
    public R success(@PathVariable("loginType") String loginType, @RequestParam("code") String code) {
        LoginStrategy strategy = LoginStrategyFactory.getStrategy(loginType);
        SocialUser user = strategy.getUserInfo(code);

        // 2、登陆
        return memberFeignService.oauthLogin(user);
    }
}
